package com.aooci.ordercat.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.aooci.ordercat.dao.OrdercatDAO;
import com.aooci.ordercat.domain.Ordercat;
import com.aooci.ordercat.enums.OrderStatus;

/**
 * A data access object (DAO) providing persistence and search support for
 * Account entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.bitongline.lgs.dao.Account
 */
public class OrdercatDAOImpl extends AbstractBaseDAOImpl<Ordercat, Integer> implements OrdercatDAO {

	public OrdercatDAOImpl() {
		super(Ordercat.class);
	}

	private static final long serialVersionUID = -4236573107157049581L;
	private static final Logger log = Logger.getLogger(OrdercatDAOImpl.class);

	@Override
	public List<Ordercat> selectByAttributes(final int year, final int month, final int day, final OrderStatus status) {
	    return getHibernateTemplate().execute(new HibernateCallback<List<Ordercat>>() {  
	        @SuppressWarnings("unchecked")
			@Override  
	        public List<Ordercat> doInHibernate(Session session)  
	            throws SQLException {  
	        	Query query = session.getNamedQuery("ORDERCAT.selectByAttributes");
	        	query.setParameter("year", year);
	        	query.setParameter("month", month);
	        	query.setParameter("day", day);
	        	query.setParameter("status", status);
	            return (List<Ordercat>)query.list();  
	        }  
	    });
	}
	
	@Override
	public List<Ordercat> selectByAcrossDayConditons(final int selectedYear, final int selectedMonth, final int selectedDay, final int nextYear, final int nextMonth, final int nextDay, final OrderStatus status, final int divideTime) {
	    return getHibernateTemplate().execute(new HibernateCallback<List<Ordercat>>() {  
	        @SuppressWarnings("unchecked")
			@Override  
	        public List<Ordercat> doInHibernate(Session session)  
	            throws SQLException {  
	        	Query query = session.getNamedQuery("ORDERCAT.selectByAcrossDayConditons");
	        	query.setParameter("selectedYear", selectedYear);
	        	query.setParameter("selectedMonth", selectedMonth);
	        	query.setParameter("selectedDay", selectedDay);
	        	query.setParameter("nextYear", nextYear);
	        	query.setParameter("nextMonth", nextMonth);
	        	query.setParameter("nextDay", nextDay);
	        	query.setParameter("status", status);
	        	query.setParameter("divideTime", divideTime);
	            return (List<Ordercat>)query.list();  
	        }  
	    });
	}
}